博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Springmvc 整合 jetbrick 实例
阅读量:5773 次
发布时间:2019-06-18

本文共 10521 字,大约阅读时间需要 35 分钟。

应用环境: 

<jetbrick.version>1.2.8</jetbrick.version>

<antlr4-runtime.version>4.2.2</antlr4-runtime.version>

<spring.mybatis.common.version>2.0</spring.mybatis.common.version>

项目结构:

实例展示:

1.引如pom依赖

4.0.0
com.spring.mybatis
jetbrick-mvc
war
0.0.1-SNAPSHOT
jetbrick-mvc Maven Webapp
http://maven.apache.org
UTF-8
1.7.7
4.11
4.1
1.1.3
1.7
1.2.8
4.2.2
2.4
jetbrick-template
jetbrick-template
${jetbrick.version}
com.spring.mybatis
spring-mybatis-data-common
2.0
org.apache.geronimo.specs
geronimo-servlet_3.0_spec
junit
junit
${junit.version}
test
org.slf4j
slf4j-api
${slf4j.version}
org.antlr
antlr4-runtime
${antlr4-runtime.version}
servlet-api
servlet-api
${servlet.version}
jetbrick-mvc

2.添加jetbrick的监听与配置文件到web.xml

org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath*:context/spring-context.xml
org.springframework.web.util.IntrospectorCleanupListener
jetbrick.template.web.JetWebEngineLoader
jetbrick-template-config-location
classpath:template/jetbrick-template.properties
org.springframework.web.util.Log4jConfigListener
log4jConfigLocation
classpath:property/log4j.properties
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
encodingFilter
/*
spring-controller
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath*:context/spring-mvc.xml
1
spring-controller
/
60
index.jsp

3.配置jetbrick的全局属性

import.packages = com.mvc.cmrn.dao, com.mvc.cmrn.model#import inner define function,once import use anywhere import.functions = jetbrick.template.runtime.JetFunctions#set autoscan is trueimport.autoscan = true#set autoscan packageimport.autoscan.packages = com.mvc.cmrn#set reloadable is truetemplate.reloadable = trueinput.encoding= UTF-8output.encoding=UTF-8template.reloadable = true#template.path  +  spring prefix +   VIEW + spring suffix (or?? template.suffix)template.path=/WEB-INF/jetx/compile.debug = truetemplate.loader = jetbrick.template.web.WebResourceLoader#more config read :http://subchen.github.io/jetbrick-template/config.html

4.定义jetbrick为应用试图

5.springmvc操作

package com.mvc.cmrn.controller;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.ModelAttribute;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.servlet.ModelAndView;import com.mvc.cmrn.model.Member;import com.mvc.cmrn.service.IMemberService;import com.spring.mybatis.data.common.controller.BaseMultiController;@Controller@RequestMapping("/member")public class MemberController extends BaseMultiController{    @Autowired    private IMemberService memberService;        @RequestMapping(value={"/{id:\\d+}/query.baidu"},method={RequestMethod.GET,RequestMethod.POST})    public ModelAndView query(HttpServletRequest request,HttpServletResponse response,@ModelAttribute("id") Long id){        Map
map = new HashMap
(); Member member = this.memberService.query(id); map.put("member", member); String viewPath = "front/detail"; return toView(viewPath, map); } @RequestMapping(value={"/lists.baidu"},method={RequestMethod.GET,RequestMethod.POST}) public ModelAndView lists(HttpServletRequest request,HttpServletResponse response){ Map
map = new HashMap
(); List
lists = this.memberService.list(); map.put("item", lists); String viewPath = "front/list"; return toView(viewPath, map); } @RequestMapping(value={"/{id:\\d+}/delete.baidu"},method={RequestMethod.GET,RequestMethod.POST}) public ModelAndView delete(HttpServletRequest request,HttpServletResponse response,@ModelAttribute("id") Long id){ Map
map = new HashMap
(); int result = this.memberService.delete(id); if(result>0){ map.put("message", "Delete OK"); }else{ map.put("message", "Delete Error"); } List
lists = this.memberService.list(); map.put("item", lists); String viewPath = "front/list"; return toView(viewPath, map); } public IMemberService getMemberService() { return memberService; } public void setMemberService(IMemberService memberService) { this.memberService = memberService; } }
package com.mvc.cmrn.controller;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.ModelAttribute;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.servlet.ModelAndView;import com.mvc.cmrn.model.Member;import com.mvc.cmrn.service.IMemberService;import com.spring.mybatis.data.common.controller.BaseMultiController;@Controller@RequestMapping("/member")public class MemberController extends BaseMultiController{    @Autowired    private IMemberService memberService;        @RequestMapping(value={"/{id:\\d+}/query.baidu"},method={RequestMethod.GET,RequestMethod.POST})    public ModelAndView query(HttpServletRequest request,HttpServletResponse response,@ModelAttribute("id") Long id){        Map
map = new HashMap
(); Member member = this.memberService.query(id); map.put("member", member); String viewPath = "front/detail"; return toView(viewPath, map); } @RequestMapping(value={"/lists.baidu"},method={RequestMethod.GET,RequestMethod.POST}) public ModelAndView lists(HttpServletRequest request,HttpServletResponse response){ Map
map = new HashMap
(); List
lists = this.memberService.list(); map.put("item", lists); String viewPath = "front/list"; return toView(viewPath, map); } @RequestMapping(value={"/{id:\\d+}/delete.baidu"},method={RequestMethod.GET,RequestMethod.POST}) public ModelAndView delete(HttpServletRequest request,HttpServletResponse response,@ModelAttribute("id") Long id){ Map
map = new HashMap
(); int result = this.memberService.delete(id); if(result>0){ map.put("message", "Delete OK"); }else{ map.put("message", "Delete Error"); } List
lists = this.memberService.list(); map.put("item", lists); String viewPath = "front/list"; return toView(viewPath, map); } public IMemberService getMemberService() { return memberService; } public void setMemberService(IMemberService memberService) { this.memberService = memberService; } }

6.获取应用路径

在全局属性配置文件jetbrick-template.properties中引入的jetbrick模板中自定义的函数.通过函数webroot()获取路径.

#for(Member member: item)
#end
ID 姓名 邮箱 查看 删除
${user.id} ${user.name} ${user.email} 查看 删除

语法说明: 

实例下载: http://files.cnblogs.com/dennisit/springmvc-jetbrick-demo.7z
转载请注明出处:[]

你可能感兴趣的文章
SpringCloud之消息总线(Spring Cloud Bus)(八)
查看>>
DLA实现跨地域、跨实例的多AnalyticDB读写访问
查看>>
实时编辑
查看>>
KVO原理分析及使用进阶
查看>>
【348天】每日项目总结系列086(2018.01.19)
查看>>
【294天】我爱刷题系列053(2017.11.26)
查看>>
Microsoft发布了Azure Bot Service和LUIS的GA版
查看>>
Google发布Puppeteer 1.0
查看>>
.NET开源现状
查看>>
可替换元素和非可替换元素
查看>>
2016/08/25 The Secret Assumption of Agile
查看>>
(Portal 开发读书笔记)Portlet间交互-PortletSession
查看>>
搭建vsftpd服务器,使用匿名账户登入
查看>>
JAVA中循环删除list中元素的方法总结
查看>>
Java虚拟机管理的内存运行时数据区域解释
查看>>
人人都会深度学习之Tensorflow基础快速入门
查看>>
ChPlayer播放器的使用
查看>>
js 经过修改改良的全浏览器支持的软键盘,随机排列
查看>>
Mysql读写分离
查看>>
Oracle 备份与恢复学习笔记(5_1)
查看>>